<style type="text/css">
    .selected-search {
        box-shadow: 0 1px 6px rgba(0,0,0,.2);
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click{
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }
    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="组织名字" prop="title">
            <i-input v-model="title" disabled></i-input>
        </Form-item>
        <Form-item label="审核人" prop="personalName">
            <p @click="getPeopelData()" class="select-click">{{personalName}}</p>
            <div v-if="selectPeopelIsShow" class="selected-search">
                <div class="search-action">
                    <i-input placeholder="审核人姓名"></i-input>
                </div>
                <div class="selected-arr">
                    <template v-for="(item,index) in principalArr">
                        <p @click="choosePeople(item.Id,item.RealName)" class="selected-item">{{item.RealName}}</p>
                    </template>
                </div>
            </div>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';

    export default {
        data() {
            return {
                formValidate: {
                },
                ruleValidate: {
                },
                title:'',
                image: '',
                principalId: '',
                principalArr: [],
                personalName: '请选择负责人',
                selectPeopelIsShow: false,
            }
        },
        mounted: function () {
            let id = this.$route.query.id;

            if (id && id.length > 0) {

                this.getDetail(id)
            }

        },

        methods: {
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                })
            },
            //获取负责人
            getPeopelData() {
                let that = this;

                let para = {
                    curPage: 1,
                    pageSize: 1000,
                };

                this.$Loading.start();

                if(that.selectPeopelIsShow){
                    that.selectPeopelIsShow =false;
                }else {
                    that.selectPeopelIsShow = true;

                    apiUtil.get(that, apiUtil.urls.userList, para, function (res) {
                        that.$Loading.finish();
                        that.principalArr = res.Msg.Arrays;
                    });
                }

            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    id: id,
                };

                apiUtil.get(that, apiUtil.urls.OrganizeDetail, para, function (res) {
                    that.$Loading.finish();
                    that.title = res.Msg.Title;
                });
            },
            //修改
            updateData: function (model) {
                let that = this;

                model.id = this.$route.query.id;
                model.peopleid = this.principalId;

                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.SetChecker, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('设置成功 ');

                    console.log('成功返回数据:',res)
                    // setTimeout(function () {
                    //     baseUtil.pageJump(that,that.$route.query.id,'CheckerList')
                    // },1000);

                });
            },


        }
    }
</script>
